package exemples.corba.callback;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;

import exemples.corba.callback.CallbackApp.Bonjour;
import exemples.corba.callback.CallbackApp.BonjourCallback;
import exemples.corba.callback.CallbackApp.BonjourCallbackHelper;
import exemples.corba.callback.CallbackApp.BonjourCallbackPOA;
import exemples.corba.callback.CallbackApp.BonjourHelper;





class BonjourCallbackServant extends BonjourCallbackPOA
{
    public void callback(String notification)
    {
        System.out.println("(appel de callback) -> "+ notification);
    }
}


public class BonjourClient
{
    static Bonjour bonjourImpl;
    
    public static void main(String args[])
    {
	try {
	    ORB orb = ORB.init(args, null);
	    POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
            rootpoa.the_POAManager().activate();

	    org.omg.CORBA.Object objRef = 
                     orb.resolve_initial_references("NameService");
	    NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

	    String name = "Bonjour";
	    bonjourImpl = BonjourHelper.narrow(ncRef.resolve_str(name));
	    
	    BonjourCallbackServant bonjourCallbackImpl = new BonjourCallbackServant();

	    org.omg.CORBA.Object ref = rootpoa.servant_to_reference(bonjourCallbackImpl);
	    BonjourCallback cref = BonjourCallbackHelper.narrow(ref);

	    bonjourImpl.say(cref, "Bonjour !");
	    System.out.println("Fin du client");

	} catch(Exception e){
	    System.out.println("ERROR : " + e);
	    e.printStackTrace(System.out);
	}
    }
}
